﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using YWTSSys.BLL;
using YWTSSys.Library;
using YWTSSys.Model;

namespace YWTSSys.Web.MachineSys.YWTSWeb.yw
{
    public partial class AddTelRecord : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.none };
            }
        }
        protected override string DWZRef
        {
            get { return "MyCustomerMasterList"; }
        }
        protected int CustomerId
        {
            get
            {
                return GetRequestValue<int>("CustomerId", 0);

            }
        }
        protected int ParTelId
        {
            get
            {
                return GetRequestValue<int>("ParTelId", 0);

            }
        }
        private CustomerInfo _objC = null;
        protected CustomerInfo objC
        {
            get
            {
                if (_objC == null)
                {
                    _objC = CustomerController.GetById(CustomerId);
                }
                return _objC;

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (CustomerId == 0)
            {
                Response.Write("请先选择一个客户");
                Response.End();
            }
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }
        private void addmenu()
        {
            TelRecordInfo obj = Request.SerializableObject<TelRecordInfo>();
            obj.客户ID = CustomerId;          
            obj.UserId = base.User.UserId;
            obj.RealName = base.User.RealName;
            obj.回访电话记录ID = ParTelId;
            decimal 通话时长 = 0m;

            DateTime enddate = GetRequestValue<DateTime>("结束通话", DateTime.Now);
            TimeSpan ts = enddate - obj.通话时间; ;

            通话时长 = ts.Seconds;
            obj.通话时长 = 通话时长;

            int 需回访天数=GetRequestValue<int>("需回访天数",0);

            AddLog(Permission.新增, obj);

            // obj.UserName = GetRequestValue<string>("dwz.orgLookup.UserName", "");

            int r = TelRecordController.Add(obj, 需回访天数);

            if (r > 0)
                SuccessJson("添加成功");
            else
            {
                ErrorJson("添加失败");
            }
        }
    }
}